import { RouteRecordRaw, createRouter, createWebHashHistory } from 'vue-router';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
// 动态导入路由模块,eager开启路由懒加载
const modules: Record<string, any> = import.meta.glob(['./modules/*.ts'], { eager: true });
console.log(modules, 'modules')
const routes: Array<RouteRecordRaw> = [
];
Object.keys(modules).forEach((key) => {
    const module = modules[key].default;
    routes.push(module);
});
const router = createRouter({
    history: createWebHashHistory(),
    routes,
});
const noStatusPage = ['/login', '/about'];
router.beforeEach(async (_to, _from, next) => {
    NProgress.start();
    const token = sessionStorage.getItem('userInfo');
    const userIsLogin = token ? true : false;
    if (userIsLogin || noStatusPage.includes(_to.path)) {
        next();
    } else {
        next('/login');
    }
});
router.afterEach((_to) => {
    NProgress.done();
});
export default router;
